#include "Engine.hh"

#include <iostream>

using namespace sirtet;
using std::make_unique;
using std::unique_ptr;

static Engine *_instance;

Engine::Engine() : root("Root")
{
}

void Engine::init(SDL_Window *window)
{
    graphics = make_unique<Graphics>(window);
}

void Engine::update()
{
    root.update();
}

void Engine::after_update()
{
    root.after_update();
    graphics->present();
}

Node &Engine::get_root()
{
    return root;
}

std::unique_ptr<Graphics> &sirtet::Engine::get_graphics()
{
    return graphics;
}

Engine *Engine::instance()
{
    if (_instance == nullptr)
    {
        _instance = new Engine();
    }
    return _instance;
}

void Engine::deinit()
{
    delete _instance;
}
